﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Backend.DAL;
using Backend.DTO;

namespace Backend.BLL
{
    public class PatientBLL
    {
        private PatientDAL patientDAL = new PatientDAL();


        public List<PatientDTO> GetPatientsByStudyId(int studyId)
        {
            List<PatientDTO> listOfPatients = new List<PatientDTO>();

            try
            {
                listOfPatients = patientDAL.GetPatientsByStudyId(studyId);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return listOfPatients;
        }

        public PatientDTO GetPatient(int id)
        {
            PatientDTO patientDTO = null;

            try
            {
                patientDTO = patientDAL.GetPatient(id);

                if (patientDTO == null)
                {
                    throw new ApplicationException("Patient not found.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return patientDTO;
        }

        public int GetTotalNumberOfPatients(int studyId)
        {
            try
            {
                return patientDAL.GetTotalNumberOfPatients(studyId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public int GetTotalNumberOfPatientsFlagged(int studyId)
        {
            try
            {
                return patientDAL.GetTotalNumberOfPatientsFlagged(studyId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public int GetTotalNumberOfPatientsReviewed(int studyId)
        {
            try
            {
                return patientDAL.GetTotalNumberOfPatientsReviewed(studyId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool UpdateFlagProperty(int studyId, int patientId, bool flagValue)
        {
            try
            {
                return patientDAL.UpdateFlagProperty(studyId, patientId, flagValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool UpdateReviewProperty(int studyId, int patientId, bool reviewValue)
        {
            try
            {
                return patientDAL.UpdateReviewProperty(studyId, patientId, reviewValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public int EtractPatients(int studyId)
        {
            try
            {
                return patientDAL.EtractPatients(studyId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
